export default {
    namespaced: true,
    state:()=>({
        stuScore: [{stuName: "Limi", score: 66}, {stuName: "网二", score: 77}, {
            stuName: "哇哈哈",
            score: 80
        }, {stuName: "张靓颖", score: 85}, {stuName: "欧阳娜娜", score: 91}, {stuName: "古力娜扎", score: 68}, {
            stuName: "张国荣",
            score: 99
        },]
    }),
    getters:{
        JGScore: state => {
            return state.stuScore.filter(
                stu => {
                    return stu.score > 70
                }
            )
        },
        /*
        评级:
        100--90 优秀  "A"
        90--80  良好   "B"
        80--70  及格   "C"
        70--0   不及格  "D"
        及格的人   "P" pass
         */
        //我们可以在一个getters的计算属性中调用其他的计算属性

        scoreGrand: (state, ww) => (str) => {
            switch (str) {
                case "A":
                    return state.stuScore.filter(stu => {
                        return stu.score >= 90;
                    });
                    break;
                case "B":
                    return state.stuScore.filter(stu => {
                        return stu.score >= 80&&stu.score<=90;
                    });
                    break;
                case "C":
                    return state.stuScore.filter(stu => {
                        return stu.score >= 70&&stu.score<=80;
                    });
                    break;
                case "D":
                    return state.stuScore.filter(stu => {
                        return stu.score<=70;
                    });
                    break;
                case "P":
                    return ww.JGScore;
                    break;
            }
        },
    },
    mutations:{
        Random(state){
            state.stuScore[Math.floor(Math.random()*state.stuScore.length)].score+=10;

        }
    },
    action:{
        luckStudent(context){
            //    可以放异步代码
            setTimeout(()=>{
                context.commit("Random");
            },2000)
        }
    },


}